//
//  CustomerController.m
//  SafPay
//
//  Created by 贺庆博 on 2018/6/19.
//  Copyright © 2018年 ebo. All rights reserved.
//

#import "CustomerController.h"
#import "SettingCell.h"
@interface CustomerController ()<UITableViewDelegate,UITableViewDataSource>
@property (strong,nonatomic) UITableView *tableView;
@property (strong,nonatomic) NSMutableArray *arrDS;

@end

@implementation CustomerController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"客服中心";
    [self initUI];
    [self getNewWork];
    // Do any additional setup after loading the view.
}
- (void)initUI
{
    [self.view addSubview:self.tableView];
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.view).insets(UIEdgeInsetsMake(8, 0, 0, 0));
    }];
}
-(void)getNewWork{
    
    NSString *path=[NSString stringWithFormat:@"%@%@",kBaseUrl,kHelpInfoList];
    [[TRRequest request] Post:path parameters:nil success:^(TRRequest *request, NSDictionary *responseDict) {
        
        
        if([[responseDict valueForKey:@"error"] integerValue]==0){
            
            NSMutableDictionary *dataDict=[NSMutableDictionary dictionaryWithDictionary:responseDict];
            [dataDict removeObjectForKey:@"error"];
            [dataDict.allKeys enumerateObjectsUsingBlock:^(NSString *  obj, NSUInteger idx, BOOL * _Nonnull stop) {
                
                SettingModel *model=[SettingModel new];
                if([obj isEqualToString:@"email"]){
                    
                   model.left=@"客服邮箱";
                }else{
                    
                    model.left=obj;
                }
                model.right=[dataDict valueForKey:obj];
                [self.arrDS addObject:model];
                
            }];
            [self.tableView reloadData];
            
        }else{
            
            [MBProgressHUD showErrorWithText:[responseDict valueForKey:@"error_msg"]];
        }
        MyLog(@"%@",responseDict);
        
    } failure:^(TRRequest *request, NSError *error) {
        
        [MBProgressHUD showErrorWithText:@"网络请求失败！"];
    }];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (UITableView *)tableView
{
    if (!_tableView) {
        _tableView = [UITableView new];
        _tableView.backgroundColor = [UIColor clearColor];
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.delegate = self;
        _tableView.dataSource = self;
        [_tableView registerNib:[UINib nibWithNibName:@"SettingCell" bundle:nil] forCellReuseIdentifier:@"SettingCell"];
    }
    return _tableView;
}
- (NSMutableArray *)arrDS
{
    if (!_arrDS) {
        _arrDS = [NSMutableArray array];
//        NSArray *arr = @[@{@"left":@"客服微信",@"right":@"safpay"},
//                         @{@"left":@"客服电报",@"right":@"safpay"},
//                         @{@"left":@"客服邮箱",@"right":@"safpay@ebo.com"}
//                         ];
//        __weak typeof (NSMutableArray *)weakArr = _arrDS;
//        [arr enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
//            SettingModel *model = [SettingModel new];
//            [model setValuesForKeysWithDictionary:obj];
//            [weakArr addObject:model];
//        }];
    }
    return _arrDS;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.arrDS.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    SettingCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SettingCell"];
    cell.model = self.arrDS[indexPath.row];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}



/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
